//
//  QAllOrderCell.m
//  QoilPublic
//
//  Created by zhuang on 16/7/5.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QAllOrderCell.h"

@interface QAllOrderCell()

@property (weak, nonatomic) IBOutlet UIImageView *redImage;
@property (weak, nonatomic) IBOutlet UIImageView *blueImage;
@property (weak, nonatomic) IBOutlet UIImageView *greenImage;


@property (weak, nonatomic) IBOutlet UIImageView *lineImageView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lineConstr;

@property (weak, nonatomic) IBOutlet UILabel *moneyLabel;

@property (weak, nonatomic) IBOutlet UILabel *timeLabel;

@property (weak, nonatomic) IBOutlet UILabel *addressLabel;

@property (weak, nonatomic) IBOutlet UILabel *messageLabel;

@property (weak, nonatomic) IBOutlet UIButton *styleButton;

@property (weak, nonatomic) IBOutlet UILabel *paystyleToOilLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constrW;

@property (weak, nonatomic) IBOutlet UILabel *dfLabel;

@property (weak, nonatomic) IBOutlet UIButton *tankerButton;

@end
@implementation QAllOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.lineImageView.backgroundColor = [QColorUtility defaultLineColor];
    self.lineConstr.constant = 0.5;
    self.redImage.layer.borderColor = [QColorUtility defaultRedColor].CGColor;
    self.redImage.layer.borderWidth = 0.5;
    self.redImage.layer.cornerRadius = 6;
    self.blueImage.layer.borderColor = [QColorUtility defaultBlueColor].CGColor;
    self.blueImage.layer.borderWidth = 0.5;
    self.blueImage.layer.cornerRadius = 6;
    self.greenImage.layer.borderColor = [UIColor greenColor].CGColor;
    self.greenImage.layer.borderWidth = 0.5;
    self.greenImage.layer.cornerRadius = 6;
    
    _styleButton.layer.cornerRadius = 1.0;
    
    _paystyleToOilLabel.layer.cornerRadius = 4.0;
    _paystyleToOilLabel.layer.borderColor = [QColorUtility defaultRedColor].CGColor;
    _paystyleToOilLabel.layer.borderWidth = 0.5;
    _paystyleToOilLabel.layer.masksToBounds = YES;
    _dfLabel.layer.cornerRadius = 4.0;
    _dfLabel.layer.borderColor = [QColorUtility defaultRedColor].CGColor;
    _dfLabel.layer.borderWidth = 0.5;
    _dfLabel.layer.masksToBounds = YES;
}


- (IBAction)styleAction:(UIButton *)sender {
//    if(_orderStyle == OrderDisPaySyle){//未支付
//        if(self.StyleBtnBlock){
//            self.StyleBtnBlock(1,_indexPath.section);
//        }
//    }else if (_orderStyle == OrderReceiveSyle){//待接单
//        if(self.StyleBtnBlock){
//            self.StyleBtnBlock(2,_indexPath.section);
//        }
//    }else if (_orderStyle == OrderSendSyle){//配送中
//        if(self.StyleBtnBlock){
//            self.StyleBtnBlock(3,_indexPath.section);
//        }
//
//    }else if (_orderStyle == OrderFinishSyle){//已完成
//        if(self.StyleBtnBlock){
//            
//            if([_model.orderType integerValue] == 5){
//               self.StyleBtnBlock(6,_indexPath.section);
//            }else if(_model.evaluate.integerValue == 0){//未评价
//                self.StyleBtnBlock(4,_indexPath.section);
//            }else if (_model.evaluate.integerValue == 1){//已评价
//                self.StyleBtnBlock(5,_indexPath.section);
//            }
//        }
//    }
    if (_orderStyle == OrderReceiveSyle) {
        if (self.StyleBtnBlock) {
            self.StyleBtnBlock(2, _indexPath.section);
        }
    }else if (_orderStyle == OrderSendSyle){
        if(self.StyleBtnBlock){
            self.StyleBtnBlock(3,_indexPath.section);
        }
    }else if (_orderStyle == OrderFinishSyle){
        
        if ([_model.orderState isEqualToString:@"6"]) {//未支付
            if(self.StyleBtnBlock){
                self.StyleBtnBlock(4,_indexPath.section);
            }

        }else if ([_model.orderState isEqualToString:@"1"]){//待评价
            if(self.StyleBtnBlock){
                self.StyleBtnBlock(5,_indexPath.section);
            }

        }else{//再来一单
            if(self.StyleBtnBlock){
                self.StyleBtnBlock(6,_indexPath.section);
            }
        }
    }
}

- (IBAction)tankAction:(UIButton *)sender {
    if (sender.tag == 86) {
        if(self.StyleBtnBlock){
            self.StyleBtnBlock(sender.tag,_indexPath.section);
        }
        
    }

}

- (void)setModel:(QAllorderListModel *)model{

    _model = model;
    if ([_model.orderState intValue] == 1||[_model.orderState intValue] == 3||[_model.orderState intValue] == 6||[_model.orderState intValue] == 4) {
        _moneyLabel.text = [NSString stringWithFormat:@"￥%@",_model.payAmount];
        
    }else{
        _moneyLabel.text = @"服务未完成待结算";
        
    }
    _timeLabel.text = [NSString stringWithFormat:@"%@",_model.serviceTime];
    _addressLabel.text = _model.address;
//    if([_model.desc isEqualToString:@"油到付款"]){
//        _paystyleToOilLabel.hidden = NO;
//        _paystyleToOilLabel.text = @"油到付款";
//        _constrW.constant = 65;
//    }else{
        _paystyleToOilLabel.hidden = YES;
//    }
//    
//    if([_model.desc isEqualToString:@"代付"]){
//        _dfLabel.hidden = NO;
//        _dfLabel.text = @"代付";
//        _constrW.constant = 35;
//    }else{
        _dfLabel.hidden = YES;
//    }
    
    
    
}

- (void)setOrderStyle:(OrderSyle)orderStyle{

    _orderStyle = orderStyle;
    self.styleButton.layer.cornerRadius = 5;
    self.styleButton.layer.masksToBounds = YES;
    if(_orderStyle == OrderDisPaySyle){//未支付
    
    }else if (_orderStyle == OrderReceiveSyle){//待接单
        
        [self.styleButton setTitle:@"取消订单" forState:UIControlStateNormal];
        self.styleButton.backgroundColor = [QColorUtility defaultBlueColor];
        [self.styleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.messageLabel.text = @"师傅尚未接单,请您耐心等候~";
        self.tankerButton.hidden = YES;

    }else if (_orderStyle == OrderSendSyle){//配送中
        
        [self.styleButton setTitle:@"联系司机" forState:UIControlStateNormal];
        self.styleButton.backgroundColor = [QColorUtility defaultBlueColor];
        [self.styleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.messageLabel.text = @"师傅正在配送,请保持电话畅通";
        self.tankerButton.hidden = YES;
        if ([_model.orderState isEqualToString:@"13"]) {
            self.tankerButton.hidden = NO;
        }else{
            self.tankerButton.hidden = YES;

        }

    }else if (_orderStyle == OrderFinishSyle){//已完成
    
        if ([_model.orderState isEqualToString:@"6"]) {//未支付
            [self.styleButton setTitle:@"确认支付" forState:UIControlStateNormal];
            self.styleButton.backgroundColor = [QColorUtility defaultBlueColor];
            [self.styleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            self.tankerButton.hidden = NO;

        }else if ([_model.orderState isEqualToString:@"1"]){//待评价
            
            NSString *str = _model.integral;
            NSString * outNumber = [NSString stringWithFormat:@"%@",@(str.floatValue)];
            NSString *score = [NSString stringWithFormat:@"评价得%@积分",outNumber];
            [self.styleButton setTitle:score forState:UIControlStateNormal];
            self.styleButton.backgroundColor = [QColorUtility defaultBlueColor];
            [self.styleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            self.tankerButton.hidden = YES;

        }else{
            [self.styleButton setTitle:@"再来一单" forState:UIControlStateNormal];
            self.styleButton.backgroundColor = [QColorUtility defaultBlueColor];
            [self.styleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            self.tankerButton.hidden = YES;
        }
        self.messageLabel.text = @"如有疑问请联系客服";
    }
}

//订单状态0:下单 1.完成支付 2.途中 3.已评价 4.订单结束 5.订单作废 6.司机已送达 8待退款.9挂单，10司机已拒单,11订单已取消,12支付宝退款中13加油中14审核成功


@end
